package com.xdqzy.baseline.common.controller;

import com.xdqzy.baseline.common.annotation.LogTag;
import com.xdqzy.baseline.common.model.RestResult;
import com.xdqzy.baseline.common.service.FileServerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * @author : winter
 * @version V1.0
 * @Title: 文件上传接口
 * @ClassName : com.ctbc.backend.common.controller.FileUploadController.java
 * @Description :
 * @date :  2020-11-03 23:18
 */
@Api(tags = "文件上传")
@RequestMapping("/api/v1/file")
@RestController
public class FileUploadController {

    @Resource
    private FileServerService fileServerService;

    @LogTag(value = "上传文件", showParam = false)
    @ApiOperation("通用上传文件接口")
    @PostMapping(value = "upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public RestResult<String> uploadFile(@ApiParam("上传文件") @RequestParam("file") MultipartFile multipartFile) {
        String url = fileServerService.uploadFile(multipartFile);
        return RestResult.buildSuccess(url);
    }
}
